package CAD;

import java.awt.Component;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

import features.Bezier;
import features.Feature;
import features.RoundFloorPocket;
import features.Step;

public class FeaturesTree  {
	
	
	private JTree tree=null;
	
	 public FeaturesTree() {
	   super();
	    DefaultMutableTreeNode top =
	       new DefaultMutableTreeNode("Features:                                    ");
	  	createNodes(top,MainFrame.features);
	                    
	  	tree=new JTree(top);
	    tree.setEditable(true);
	}
	 public void refreshTree(){
		 DefaultMutableTreeNode top =
		       new DefaultMutableTreeNode("Features:                                    ");
		  	createNodes(top,MainFrame.features);
		tree=new JTree(top);
		    tree.setEditable(true);
	 }
	 private void createNodes(DefaultMutableTreeNode top, ArrayList<Feature> features) {
		 
		 //<root nodes>
		 DefaultMutableTreeNode hole = new DefaultMutableTreeNode("Hole:");
		 DefaultMutableTreeNode slot = new DefaultMutableTreeNode("Slot:");
		 DefaultMutableTreeNode pocket = new DefaultMutableTreeNode("Pocket:");
		 DefaultMutableTreeNode planarFace = new DefaultMutableTreeNode("Planar Face:");
		 DefaultMutableTreeNode step = new DefaultMutableTreeNode("Step:");
		 
		 top.add(hole);
		 //<hole nodes>
		
		 DefaultMutableTreeNode blindHole = new DefaultMutableTreeNode("Blind Hole:");
		 hole.add(blindHole);
		 DefaultMutableTreeNode throughHole = new DefaultMutableTreeNode("Through Hole:");
		 hole.add(throughHole);
		 DefaultMutableTreeNode flatHoleBottom = new DefaultMutableTreeNode("Flat Hole Bottom:");
		 blindHole.add(flatHoleBottom);
		 DefaultMutableTreeNode flatWithRadiusHoleBottom = new DefaultMutableTreeNode("Flat with Radius Hole Bottom:");
		 blindHole.add(flatWithRadiusHoleBottom);
		 DefaultMutableTreeNode conicalHoleBottom = new DefaultMutableTreeNode("Conical Hole Bottom:");
		 blindHole.add(conicalHoleBottom);
		 DefaultMutableTreeNode sphericalHoleBottom = new DefaultMutableTreeNode("Spherical Hole Bottom:");
		 blindHole.add(sphericalHoleBottom);
		 
		 top.add(slot);
		 //<slot nodes>
		 DefaultMutableTreeNode linearProfile = new DefaultMutableTreeNode("Linear Profile:");
		 slot.add(linearProfile);
		 DefaultMutableTreeNode roundedUProfile = new DefaultMutableTreeNode("Rounded U Profile:");
		 slot.add(roundedUProfile);
		 DefaultMutableTreeNode veeProfile = new DefaultMutableTreeNode("Vee Profile:");
		 slot.add(veeProfile);
		 DefaultMutableTreeNode partialCircularProfile = new DefaultMutableTreeNode("Partial Circular Profile:");
		 slot.add(partialCircularProfile);
		 DefaultMutableTreeNode squareUProfile = new DefaultMutableTreeNode("Square U Profile:");
		 slot.add(squareUProfile);
		 DefaultMutableTreeNode generalProfile = new DefaultMutableTreeNode("General Profile:");
		 slot.add(generalProfile);
		 DefaultMutableTreeNode bezierPath = new DefaultMutableTreeNode("Bezier Path:");
		 generalProfile.add(bezierPath);
		 
		 top.add(pocket);
		 //<pocket nodes>
		 DefaultMutableTreeNode planarFloorPocket = new DefaultMutableTreeNode("Planar Floor Pocket:");
		 pocket.add(planarFloorPocket);
		 DefaultMutableTreeNode roundFloorPocket = new DefaultMutableTreeNode("Round Floor Pocket:");
		 pocket.add(roundFloorPocket);
		 
		 top.add(planarFace);
		 top.add(step);

		 DefaultMutableTreeNode temp = null;

		    for(int i=0;i < features.size();i++){
		    	temp = new DefaultMutableTreeNode(((Feature) features.get(i)).getName()+i+"");
		    	temp.add(
	    				new DefaultMutableTreeNode(
	    				"Face:"+((Feature) features.get(i)).placement.getFace())
	    				);
		    	temp.add(
	    				new DefaultMutableTreeNode(
	    				"Position X:"+((Feature) features.get(i)).placement.getX()+"mm")
	    				);
	    		temp.add(
	    				new DefaultMutableTreeNode(
	    				"Position Y:"+((Feature) features.get(i)).placement.getZ()+"mm")
	    				);
	    		temp.add(
	    				new DefaultMutableTreeNode(
	    				"Position Z:"+((Feature) features.get(i)).placement.getY()+"mm")
	    				);
	    		
		    	if(((Feature) features.get(i)).getType()==Feature.BEZIERPATH){
		    		bezierPath.add(temp); 
		    	   ((Feature) features.get(i)).drawNode(temp);
		    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.CONICALHOLEBOTTOM){
		    		conicalHoleBottom.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.FLATHOLEBOTTOM){
		    		flatHoleBottom.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.FLATWITHRADIUSHOLEBOTTOM){
		    		flatWithRadiusHoleBottom.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.LINEARPROFILE){
		    		linearProfile.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.PARTIALCIRCULARPROFILE){
		    		partialCircularProfile.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.PLANARFACE){
		    		planarFace.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.PLANARFLOORPOCKET){
		    		planarFloorPocket.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.ROUNDEDUPROFILE){
		    		roundedUProfile.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.ROUNDFLOORPOCKET){
		    		roundFloorPocket.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.SPHERICALHOLEBOTTOM){
		    		sphericalHoleBottom.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.SQUAREUPROFILE){
		    		squareUProfile.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.STEP){
		    		step.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.THROUGHHOLE){
		    		throughHole.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	else if(((Feature) features.get(i)).getType()==Feature.VEEPROFILE){
		    		veeProfile.add(temp); 
			    	((Feature) features.get(i)).drawNode(temp);
			    	}
		    	
		    }
		    
		    
		  
		}

	public Component getTree() {
		// TODO Auto-generated method stub
		return tree;
	}

	
}
